package com.atguigu.daijia.customer.controller;

import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.customer.service.CustomerInfoService;
import com.atguigu.daijia.model.form.customer.UpdateWxPhoneForm;
import com.atguigu.daijia.model.vo.customer.CustomerLoginVo;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/customer/info")
@SuppressWarnings({"unchecked", "rawtypes"})
@RequiredArgsConstructor
public class CustomerInfoController {

	private final CustomerInfoService customerInfoService;

	/**
	 * 微信小程序登录接口
	 * @param code 微信小程序临时登录凭证
	 * @return
	 */
	@Operation(summary = "微信小程序登录接口")
	@GetMapping("/login/{code}")
	public Result<Long> login(@PathVariable("code") String code) {
		return Result.ok(customerInfoService.login(code));
	}

	/**
	 * 根据用户 ID 获取用户基本信息
	 * @param customerId
	 * @return
	 */
	@Operation(summary = "获取用户基本信息")
	@GetMapping("/getCustomerLoginInfo/{customerId}")
	public Result<CustomerLoginVo> getCustomerLoginInfo(@PathVariable Long customerId) {
		CustomerLoginVo customerLoginVo = customerInfoService.getCustomerLoginInfo(customerId);
		return Result.ok(customerLoginVo);
	}

	/**
	 * 绑定用户手机号
	 * @param updateWxPhoneForm
	 * @return
	 */
	@Operation(summary = "绑定用户手机号")
	@PostMapping("/updateWxPhoneNumber")
	public Result<Boolean> updateWxPhoneNumber(@RequestBody UpdateWxPhoneForm updateWxPhoneForm) {
		return Result.ok(customerInfoService.updateWxPhoneNumber(updateWxPhoneForm));
	}

	/**
	 * 获取乘客 OpenId
	 * @param customerId
	 * @return
	 */
	@Operation(summary = "获取乘客 OpenId")
	@GetMapping("/getCustomerOpenId/{customerId}")
	public Result<String> getCustomerOpenId(@PathVariable("customerId") Long customerId) {
		String openId = customerInfoService.getCustomerOpenId(customerId);
		return Result.ok(openId);
	}
}

